﻿using Autofac;
using IdentityService.Domain.Services;
using IdentityService.Infrastructure;

namespace IdentityService.Application
{
    public class AppModule : Module
    {
        protected override void Load(ContainerBuilder builder)
        {
            var domainAssembly = typeof(UserAccountService).Assembly;
            var infrastructureAssembly = typeof(AppIdentityDbContext).Assembly;
            var applicationAssembly = typeof(AppModule).Assembly; 

            builder.RegisterAssemblyTypes(domainAssembly, infrastructureAssembly)
                .Where(t => t.Name.EndsWith("Repository"))
                .AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(domainAssembly)
                .Where(t => t.Name.EndsWith("Service"))
                .AsImplementedInterfaces();

            builder.RegisterAssemblyTypes(applicationAssembly)
                .Where(t => t.Name.EndsWith("Service"))
                .AsImplementedInterfaces();
        }
    }
}
